__all__ = [ "Model", "ModelTrait", "Weapon", "WeaponTrait" ]

from google.appengine.ext import db

class Model(db.Model):
    label = db.StringProperty()
    name = db.StringProperty()
    
    chassis = db.StringProperty()
    variants = db.StringProperty()
    
    faction = db.StringProperty()
    image = db.StringProperty()    
    
    detect = db.IntegerProperty()
    sensors = db.IntegerProperty()
    comm = db.IntegerProperty()
    autocomm = db.IntegerProperty()
    
    armor = db.IntegerProperty()
    size = db.IntegerProperty()
    
    damage = db.StringProperty()
    
    pMoveType = db.StringProperty()
    pSpeedCbt = db.IntegerProperty()
    pSpeedTop = db.IntegerProperty()
    
    sMoveType = db.StringProperty()
    sSpeedCbt = db.IntegerProperty()
    sSpeedTop = db.IntegerProperty()
        
    author = db.UserProperty()    
    date = db.DateTimeProperty(auto_now_add=True)
    
    ''' Returns a dictionary for JSON encoding '''
    def serialize(self): 
        return {
            "key" : str(self.key()),
            "label": self.label,
            "name" : self.name,
            
            "chassis" : self.shortDesc,
            "variants" : self.fullDesc,
            
            "detect" : self.detect,
            "sensors" : self.sensors,
            "comm" : self.comm,
            "autocomm" : self.autocomm,
            
            "armor" : self.armor,
            "size" : self.size,
            
            "damage" : self.damage,
            
            "pMoveType" : self.pMoveType,
            "pSpeedCbt" : self.pSpeedCbt,
            "pSpeedTop" : self.pSpeedTop,
            
            "sMoveType" : self.sMoveType,
            "sSpeedCbt" : self.sSpeedCbt,
            "sSpeedTop" : self.sSpeedTop,
            
            "author" : self.author,            
            "date" : self.date.ctime()
        }          
    
class Weapon(db.Model):
    label = db.StringProperty()
    name = db.StringProperty()
    
    shortDesc = db.StringProperty()
    fullDesc = db.StringProperty()
            
    accuracy = db.IntegerProperty()
    damage = db.IntegerProperty()
    maxRange = db.IntegerProperty()
    
    isInfinite = db.BooleanProperty()
    
    author = db.UserProperty()    
    date = db.DateTimeProperty(auto_now_add=True)
    
    ''' Returns a dictionary for JSON encoding '''
    def serialize(self): 
        return {
            "key" : str(self.key()),
            "label": self.label,
            "name" : self.name,
            "sDesc" : self.shortDesc,
            "fDesc" : self.fullDesc,
            
            "accuracy" : self.accuracy,
            "damage" : self.damage,
            "maxRange" : self.maxRange,
            
            "author" : self.author,            
            "date" : self.date.ctime()
        }      

''' Traits are identical, could be combined but without 
    references may be better to have them separate
    '''
class ModelTrait(db.Model):
    label = db.StringProperty()
    name = db.StringProperty()
       
    shortDesc = db.StringProperty()
    fullDesc = db.StringProperty()
    
    author = db.UserProperty()    
    date = db.DateTimeProperty(auto_now_add=True)
    
    ''' Returns a dictionary for JSON encoding '''
    def serialize(self): 
        return {
            "key" : str(self.key()),
            "label": self.label,
            "name" : self.name,
            "sDesc" : self.shortDesc,
            "fDesc" : self.fullDesc,
            "author" : self.author,            
            "date" : self.date.ctime()
        }     
    
class WeaponTrait(db.Model):        
    label = db.StringProperty()
    name = db.StringProperty()
       
    shortDesc = db.StringProperty()
    fullDesc = db.StringProperty()
    
    author = db.UserProperty()    
    date = db.DateTimeProperty(auto_now_add=True)
    
    ''' Returns a dictionary instance for JSON encoding '''
    def serialize(self): 
        return {
            "key" : str(self.key()),
            "label": self.label,
            "name" : self.name,
            "sDesc" : self.shortDesc,
            "fDesc" : self.fullDesc,
            "author" : self.author,            
            "date" : self.date.ctime()
        }      

    ''' Interpret a dictionary from JSON as a WeaponTrait '''
    def deserialize(self, dict):
        foo=1 
